package com.sgfm.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertyUtils {

	private static Properties properties = new Properties();

	private static Logger logger = Logger.getLogger(PropertyUtils.class);

	static {
		String configPath = Thread.currentThread().getContextClassLoader()
								.getResource("config.properties").getPath();
		InputStream inSteam = null;
		try {
			inSteam = new FileInputStream(configPath);
			properties.load(inSteam);
		} catch (FileNotFoundException e) {
			logger.error(e.getMessage(), e);
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		} finally {
			try {
				if (inSteam != null) {
					inSteam.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static String getValue(String key){
		return properties.getProperty(key);
	} 
	
	public static String getValue(String key, String defaultValue){
		return properties.getProperty(key, defaultValue);
	} 
}
